//
//  InvestEventDao.m
//  investevent
//
//  Created by jiangshao on 16/3/6.
//  Copyright © 2016年 com.scj.investevent. All rights reserved.
//

#import "InvestEventDao.h"

@implementation InvestEventDao






-(void)getInvestEvent:(NSString *)date{
    
    NSString *url=[NSString stringWithFormat: @"http://comment.10jqka.com.cn/tzrl/getTzrlData.php?type=data&date=%@",date];
    
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer = [AFHTTPResponseSerializer serializer];
//    session.requestSerializer = [AFHTTPRequestSerializer serializer];
//    session.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
//    session.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingMutableContainers];
//    session.responseSerializer = [AFJSONResponseSerializer
//                                         serializerWithReadingOptions:NSJSONReadingAllowFragments];
    
    [session GET:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
             NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
        
        NSString * encodeStr = [[NSString alloc] initWithBytes:[responseObject bytes] length:[responseObject length] encoding:enc];
        
        NSDictionary *responseDict=[self dictionaryWithJsonString:encodeStr];

        
        NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
        [dict setObject:responseDict forKey:@"getInvestEvent"];

        [self.remoteDaoDelegate getRemotedata:dict];
        NSLog(@"成功");
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"失败");
        NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];
        [dict setObject:@"getInvestEvent" forKey:Fail];
//        [self.remoteDaoDelegate getRemoteFail:dict];
    }];
    
}

- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString
{
    if (jsonString == nil) {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err)
    {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}

@end
